User Settings file in sys folder

James Peret 8 years ago
parent
commit
b476818064

+ 34 - 1
app/scripts/services/file-service.js

@@ -1,7 +1,40 @@
1 1
 angular.module('codexApp')
2 2
 .service('FileService', [ '$rootScope', '$http', 'ThumbnailService', '$state',  function($rootScope, $http, ThumbnailService, $state) {
3 3
 
4
-  var notes_dir = "/Users/james/dev/codex/codex";
4
+  var getAppData = function(){
5
+    var remote = require('remote');
6
+    var app = remote.require('app');
7
+    var appDataPath = app.getPath("userData");
8
+    var defaultUserContentPath = app.getPath("home") + "/Documents";
9
+    findOrGenerateUserDataFile(appDataPath, defaultUserContentPath);
10
+    var raw_data = fs.readFileSync(appDataPath + '/userData.json', 'utf8');
11
+    var data = JSON.parse(raw_data);
12
+    console.log(data);
13
+    return data
14
+  }
15
+
16
+  var findOrGenerateUserDataFile = function(path, defaultUserContentPath) {
17
+    var generate_settings = true;
18
+    fs = require('fs')
19
+    fs.readdirSync(path).forEach(function(file) {
20
+      if(file == "UserData.json"){
21
+        console.log("-> Loading Settings");
22
+        generate_settings = false;
23
+      }
24
+    });
25
+    if (generate_settings){
26
+      // Generate file
27
+      file_path = path + "/UserData.json";
28
+      console.log("-> Generating user settings file: '" + file_path + "'");
29
+      var content = '{ "UserDataDirectory" : "' + defaultUserContentPath +'" }';
30
+      fs.writeFileSync(file_path, content, 'utf8');
31
+      return true;
32
+    }
33
+  }
34
+
35
+  var appData = getAppData();
36
+
37
+  var notes_dir = appData.UserDataDirectory;
5 38
   var default_notes_dir = "/Users/james/dev/codex/codex/inbox";
6 39
   var default_home_note = "/Users/james/dev/codex/codex/index.md"
7 40
   var notes = [];

+ 33 - 32
app/scripts/services/thumbnail-service.js

@@ -2,39 +2,40 @@ angular.module('codexApp')
2 2
 .service('ThumbnailService', [ '$rootScope', '$http',  function($rootScope, $http) {
3 3
 
4 4
   var createThumbnail = function(file_path) {
5
-    //console.log("-> Creating Thumbnail for " + file_path);
6
-    var webshot = require('webshot');
7
-    var fs      = require('fs');
8
-    var marked = require('marked');
9 5
 
10
-    var options = {
11
-      screenSize: {
12
-        width: 220
13
-      , height: 170
14
-      }
15
-    , shotSize: {
16
-        width: 220
17
-      , height: '170'
18
-      }
19
-    , userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)'
20
-        + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g'
21
-    , siteType:'html'
22
-    };
23
-
24
-    var data = fs.readFileSync(file_path);
25
-    var page_data = String.fromCharCode.apply(null, data);
26
-
27
-    var thumbnail_path = getThumbnailName(file_path);
28
-    var page = '<html><head><style>body {width: 210px;} body, h1, h2, h3, h4, h5, p, span, table, code, ul, ol { font-family: helvetica; overflow-wrap: break-word; font-weight: 300; } p, ul, ol, code { font-size: 11px;} h1 {font-size: 16px;} h2 {font-size: 14px;} h3 { font-size: 12px; font-weight: 400} code { font-family: monospace; }</style></head><body>' + marked(page_data); + '</body></html>';
29
-    var renderStream = webshot(page, thumbnail_path, options, function(err) {
30
-      // screenshot now saved to hello_world.png
31
-    });
32
-    //var file = fs.createWriteStream('google.png', {encoding: 'binary'});
33
-
34
-
35
-
36
-    console.log("-> Created thumbnail " + thumbnail_path);
37
-    return thumbnail_path;
6
+    // //console.log("-> Creating Thumbnail for " + file_path);
7
+    // var webshot = require('webshot');
8
+    // var fs      = require('fs');
9
+    // var marked = require('marked');
10
+    //
11
+    // var options = {
12
+    //   screenSize: {
13
+    //     width: 220
14
+    //   , height: 170
15
+    //   }
16
+    // , shotSize: {
17
+    //     width: 220
18
+    //   , height: '170'
19
+    //   }
20
+    // , userAgent: 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us)'
21
+    //     + ' AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g'
22
+    // , siteType:'html'
23
+    // };
24
+    //
25
+    // var data = fs.readFileSync(file_path);
26
+    // var page_data = String.fromCharCode.apply(null, data);
27
+    //
28
+    // var thumbnail_path = getThumbnailName(file_path);
29
+    // var page = '<html><head><style>body {width: 210px;} body, h1, h2, h3, h4, h5, p, span, table, code, ul, ol { font-family: helvetica; overflow-wrap: break-word; font-weight: 300; } p, ul, ol, code { font-size: 11px;} h1 {font-size: 16px;} h2 {font-size: 14px;} h3 { font-size: 12px; font-weight: 400} code { font-family: monospace; }</style></head><body>' + marked(page_data); + '</body></html>';
30
+    // var renderStream = webshot(page, thumbnail_path, options, function(err) {
31
+    //   // screenshot now saved to hello_world.png
32
+    // });
33
+    // //var file = fs.createWriteStream('google.png', {encoding: 'binary'});
34
+    //
35
+    //
36
+    //
37
+    // console.log("-> Created thumbnail " + thumbnail_path);
38
+    // return thumbnail_path;
38 39
   }
39 40
 
40 41
   var getThumbnailName = function(file_path) {

+ 1 - 0
codex/dev/codex-app/notes.md

@@ -10,6 +10,7 @@ Links, snipets and references for the Codex App.
10 10
 * [Wavesurfer.js](http://wavesurfer-js.org/) - Web Audio Waveform Visualizer
11 11
 * [Cheerio](https://github.com/cheeriojs/cheerio) - Fast, flexible, and lean implementation of core jQuery designed specifically for the server
12 12
 * [angular-inview](https://github.com/thenikso/angular-inview) - AngularJS directive to check if a DOM element is in the browser viewport.
13
+* [ShareJS](https://github.com/share/ShareJS) - Collaborative editing in any app
13 14
 
14 15
 ## Reading
15 16
 

+ 7 - 1
codex/index.md

@@ -13,4 +13,10 @@
13 13
 * [Todo's](dev/codex-app/todos.md)
14 14
 * [Notes](dev/codex-app/notes.md) 
15 15
 * [Highlight JS](dev/codex-app/highlightjs.md)
16
-* [Encryption](dev/codex-app/Encryption.md)
16
+* [Encryption](dev/codex-app/Encryption.md)
17
+
18
+## Trip
19
+
20
+* [Planning](Notes/Trip 2016/planning.md) ⭐
21
+* [Job Search](Notes/Job Search/index.md)
22
+* [J1X Server](inbox/j1x-server.md)

+ 5 - 0
css/codex.css

@@ -151,6 +151,11 @@ code.hljs .hljs-title {
151 151
   margin-right: 6px;
152 152
 }
153 153
 
154
+.hljs-number, .hljs-preprocessor, .hljs-pragma, .hljs-built_in, .hljs-literal, .hljs-params, .hljs-constant {
155
+  padding-left: 7px;
156
+  padding-right: 7px;
157
+}
158
+
154 159
 .icon-tabs {
155 160
     margin: 0px;
156 161
     margin-left: -34px;